#include "czDisplay.h"
#include "ContextEGL1.h"

#include "InputListenerDefault.h"

#include <GLES/gl.h>
#include "glue.h"

#ifdef _WIN32
#pragma comment (lib, "libgles_cm.lib")
#endif

void To3DMode(int w, int h)
{
  glViewport(0, 0, w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluePerspectivef(60.0f, (GLfloat)w/(GLfloat)w, 1.0f, 200.0f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void To2DMode(int w, int h)
{
  glViewport(0,0, w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  //glFrustumf(-(w/2),w/2, -h/2,h/2, 1.0f, 200.0f);
  glOrthof(-(w/2),w/2, -h/2,h/2, 1.0f, 200.0f); // left-upper as (-w/2,h/2)
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

int main(int argc, char** argv)
{
  ContextEGL1 ctx;
  MyListener li;
  WindowClass window(&ctx, &li, "title", 640, 480);
  window.center();
  window.show();

  glEnable(GL_CW);
  glCullFace(GL_BACK);

  To2DMode(window.getWidth(),window.getHeight());


  // Clears the screen in different colours
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // clear blue

  while(window.isRun())
  {
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();							// Reset The Current Modelview Matrix

    glFlush();
    window.update();
  }

  return 0;
}
